// ****************************************************************************
// @File: GlobalDefinition.h
//
// PURPOSE: common macro and consts
// AUTHOR:  Zj Ai
//
// NOTES: 
//     
// HISTORY:
//
//   ------ Zj Ai  05/07/2012 creating the file
//
// @EndHeader@
// ****************************************************************************

#pragma once
#include "stdafx.h"
#include <Windows.h>

// the finalize for all the object
typedef void (*DESTORY_PROC)(void*);

// object release&delete macros
#define DELETE_IF_NOT_NULL(x)           if((x)!=NULL){delete(x);(x)=NULL;}
#define DELETE_ARRAY_IF_NOT_NULL(x)     if((x)!=NULL){delete[] (x);(x)=NULL;}
#define FREE_IF_NOT_NULL(x)             if((x)!=NULL){free(x);(x)=NULL;}
#define RELEASE_IF_NOT_NULL(x)          if((x)!=NULL){(x)->Release();(x)=NULL;}
#define CLOSE_HANDLE_IF_NOT_NULL(x)     if((x)!=NULL){::CloseHandle(x);(x)=NULL;}
#define CLOSE_FILEHANDLE_IF_VALID(x)    if(((x) != INVALID_HANDLE_VALUE) && ((x) != NULL)) {::CloseHandle(x);(x)=INVALID_HANDLE_VALUE;}
#define DISPOSE_IF_NOT_NULL(x)          if((x)!=NULL){(x)->Dispose();(x)=NULL;}


#define GENERATIONS_NUM 3

#define GENERATIONS_2_BYTES_LIM (1024)
#define GENERATIONS_1_BYTES_LIM (3*GENERATIONS_2_BYTES_LIM)
#define GENERATIONS_0_BYTES_LIM (5*GENERATIONS_2_BYTES_LIM)